<template>
  <div class="mainContainer">
    <img class="background" src="../assets/login/background.jpg"/>
    <div class="findbackPasswordThird">
      <h1 style="margin-left: 35%">修改密码</h1>
      <div class="inputs">
        <div>
          <span class="label" style="margin-left: 5px;">密码：</span>
          <el-input :style="margin" class="input" type="password" v-model="password"/>
        </div>
        <div>
          <span class="label" style="margin-right: 0px;">重复密码：</span>
          <el-input style="width: 200px" class="input" type="password" v-model="password_repeat" @input="checkPassword()"></el-input>
          <img :src="img" class="state-img"/>
        </div>
      </div>
      <el-button style="margin-left: 15%;margin-top: 20px;" class="submit" type="primary" @click="change()">更改</el-button>
    </div>
  </div>
</template>

<script>
import findbackPassword from '@/api/findback_password'
import ParseRequest from '@/utils/requestutil';

export default {
  name: "findback-pasword-third",
  data () {
    return {
      img_right: require('../assets/register/dui.jpg'),
      img_wrong: require('../assets/register/cuo.jpg'),
      img: '',
      password: '',
      password_repeat: '',
      margin: 'margin-left: 20px',
      isPasswordCorrect: false
    }
  },
  methods: {
    checkPassword: function () {
      if (this.password === this.password_repeat) {
        this.img = this.img_right
        this.isPasswordCorrect = true
      } else {
        this.img = this.img_wrong
        this.isPasswordCorrect = false
      }
      this.margin = 'margin-left: 10px'
    },
    change: function () {
      let url = window.location.href
      let parser = new ParseRequest(url)
      let rePasswordToken = parser.getParam('repassToken')
      if (! this.isPasswordCorrect){
        this.$message.error("密码不匹配！")
        return
      }
      findbackPassword.changePassword(this, this.password, rePasswordToken)
    }
  }
}
</script>

<style scoped>
  .mainContainer{
    width: 100%;
    height: 100%;
    display: flex;
    position: relative;
  }
  .background{
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    filter: blur(1px);
  }
  .findbackPasswordThird{
    width: 400px;
    height: 700px;
    background: white;
    border-radius: 15px;
    border: 1px solid #AEAEAE;
    position: absolute;
    z-index: 2;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    box-shadow: 2px 2px 20px #888;
  }
  .inputs{
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction:column;
  }
  .input{
    margin-top: 10px;
    width: 200px;
    float: none;
    overflow: visible;
  }
  .submit{
    margin-top: 10px;
    width: 70%;
  }
</style>
